<template>
  <div class="app-header-userinfo">
            <el-dropdown trigger="click" :hide-on-click="false">
              <span class="el-dropdown-link" style="color:white">
                {{userName}}
                <i class="el-icon-arrow-down el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item>我的消息</el-dropdown-item>
                <el-dropdown-item>设置</el-dropdown-item>
                <el-dropdown-item divided @click.native="logout">退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
</template>
<script>
import Cookies from "js-cookie";
export default {
  data(){
    return{
      userName:null
    }
  },
  methods:{
    logout: function() {
      this.$confirm("确认退出?", "提示", {})
        .then(() => {
          sessionStorage.removeItem("user");
           this.deleteCookie("token");
          this.$router.push("/login");
        })
        .catch(() => {});
    },
     // 删除cookie
    deleteCookie: function(name) {
      Cookies.remove(name);
    },
  },
    mounted: function() {
    let user = sessionStorage.getItem("user");
    if (user) {
      this.userName = user;
    }

  }
}
</script>
